/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lt.cj.core.utils;

import org.lt.cj.config.entities.ConfigModel;
import org.lt.cj.core.Seed;
import org.lt.cj.core.entity.Entity;
import org.lt.cj.core.entity.TMallEntity;
import org.lt.cj.core.filters.EntityFilter;
import org.lt.cj.core.filters.TMallEntityFilter;

/*
 * @author luohong
 * 过滤出数据实体并保存
 */
public class FiltDataThread implements Runnable {

    private ConfigModel configModel;
    private Seed seed;

    public FiltDataThread(ConfigModel configModel, Seed seedURL) {

        this.configModel = configModel;
        this.seed = seedURL;
    }

    public void filtAndSaveEntity(Seed seed) {
        //        qaaEntityFilter = new QAAEntityFilter(configModel);
        EntityFilter filter = new TMallEntityFilter(configModel);
        System.out.println("pName:" + seed.getSortName());
        System.out.println("pUrl:" + seed.getUrl());
        System.out.println("pSort:" + seed.getSortName());
        Entity entity = filter.filtEntity(seed);
        TMallEntity tmallEntity = (TMallEntity) entity;

//        QuestionAndA qanda = qaaEntityFilter.filtEntity(visitUrl);
//        if (qanda != null && !qanda.getQuestion().trim().equals("")) {        //如果没有过滤到数据实体，则说明url不匹配
//            IQuestionAndA dao = new DataCommunicate();
//            qanda.setTaskName(configModel.getTaskName());
//            dao.saveQuestionAndA(qanda, configModel.getOrigLanguage(), configModel.getTranLanguage());
//        }
    }

    public void run() {
        filtAndSaveEntity(seed);
    }
}
